package com.app.base.service.core.personnel.controller;


import com.alibaba.fastjson.JSONObject;
import com.app.base.service.core.personnel.entity.PersonInfo;
import com.app.base.service.core.personnel.service.PersonInfoService;
import com.app.base.utlis.auth.JwtHelper;
import com.app.base.utlis.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 人才档案 前端控制器
 * @author yuhag
 * @since 2022-05-11
 */
@RestController
@RequestMapping("/personInfoController")
@Api(tags = "人才档案")
@CrossOrigin
public class PersonInfoController {

    @Resource
    private PersonInfoService personInfoService;

    @PostMapping("saveOrUpdatePersonInfo")
    @ApiOperation("更新或添加人才档案信息")
    public Result saveOrUpdatePersonInfo(HttpServletRequest request,@RequestBody PersonInfo personInfo){
        String userId = JwtHelper.getMemberIdByJwtToken(request);
        return personInfoService.saveOrUpdatePersonInfo(userId,personInfo);
    }

    @GetMapping("pagePersonInfo")
    @ApiOperation("搜索分页显示人才档案信息")
    public Result pagePersonInfo(@RequestParam(value = "current" ,defaultValue = "1") Long current,
                                 @RequestParam(value = "pageSize",defaultValue = "5")Long pageSize,
                                 @RequestParam(value = "startTime",required = false)String startTime,
                                 @RequestParam(value = "endTime",required = false)String endTime,
                                 @RequestParam(value = "name",required = false)String name,
                                 @RequestParam(value = "education",required = false)Integer education,
                                 @RequestParam(value = "expectedPosition",required = false)String expectedPosition,
                                 @RequestParam(value = "graduationSchool",required = false)String graduationSchool,
                                 @RequestParam(value = "reviewer",required = false)String reviewer){
        return personInfoService.pagePersonInfo(current,pageSize,startTime,endTime,name,education,expectedPosition,reviewer,graduationSchool);
    }


    @GetMapping("pagePersonAdopt")
    @ApiOperation("分页显示通过面过面试人才档案信息")
    public Result pagePersonAdopt(@RequestParam(value = "current" ,defaultValue = "1") Long current,
                                  @RequestParam(value = "pageSize",defaultValue = "10")Long pageSize){
        return personInfoService.pagePersonAdopt(current, pageSize);
    }

    @DeleteMapping("delPersonInfo/{id}")
    @ApiOperation("删除人才档案信息")
    public Result deletePerson(HttpServletRequest request,
                               @PathVariable("id")String id,
                               @RequestBody JSONObject json){
        String description = json.getString("description");
        String userId = JwtHelper.getMemberIdByJwtToken(request);
        return personInfoService.deletePerson(userId,description,id);
    }


    @GetMapping("getPersonInfoById/{id}")
    @ApiOperation("根据id获取人才信息")
    public Result getPersonInfoById(@PathVariable("id")String id){
        return personInfoService.getPersonInfoById(id);
    }

    @PostMapping("emailNotice/{id}")
    @ApiOperation("邮件通知")
    public Result emailNotice(@RequestBody JSONObject json,@PathVariable("id")String id){
        String content = json.getString("content");
        return personInfoService.emailNotice(content,id);
    }

    @PostMapping("passTheInterview/{id}")
    @ApiOperation("通过面试")
    public Result passTheInterview(HttpServletRequest request,@RequestBody JSONObject json,@PathVariable("id")String id){
        String userId = JwtHelper.getMemberIdByJwtToken(request);
        return personInfoService.passTheInterview(json,id,userId);
    }

}

